package com.bp.hearthealth.pulse.lnapps.bp_ui.bp_dialog

import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import android.widget.TextView
import com.bp.hearthealth.pulse.lnapps.R
import com.bp.hearthealth.pulse.lnapps.bp_extension.BpGlobalUtil
import com.bp.hearthealth.pulse.lnapps.bp_utils.DoubleClickListener

class BpGuideCamarePopup(context: Activity) {

    private val popupView: View
    private val popupWindow: PopupWindow
    private val context = context

    init {
        val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        popupView = inflater.inflate(R.layout.guide_camare_layout_bg, null)
        val gotIt = popupView.findViewById<TextView>(R.id.tv_got_it)
        popupWindow = PopupWindow(
            popupView,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            true
        )
        gotIt.setOnClickListener(object : DoubleClickListener() {
            override fun onNoDoubleClick(v: View?) {
                popupWindow.dismiss()
                onCliclLisener.gotIt()
            }
        })
        popupWindow.setOnDismissListener {
            BpGlobalUtil.setBackgroundAlpha(context, 1f)
        }
        popupWindow.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
    }

    fun showAtLocation(anchor: View, gravity: Int, xOff: Int, yOff: Int) {
        if (!popupWindow.isShowing) {
            BpGlobalUtil.setBackgroundAlpha(context, 0.2f)
            popupWindow.showAtLocation(anchor, gravity, xOff, yOff)
        }
    }

    private lateinit var onCliclLisener: OnGotItListener

    fun setOnGotItListener(clickListener: OnGotItListener) {
        this.onCliclLisener = clickListener
    }

    interface OnGotItListener {
        fun gotIt()
    }
}
